package com.pengli.mytools.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.TelephonyManager;

public class TelePhoneUtil {
    private static String TAG = "TelePhoneUtil";
    private TelephonyManager telephonyManager;
    private String NetworkOperator;
    private Context context;

    public TelePhoneUtil(Context context) {
        this.context = context;
        telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    }

    //获取sim卡iccid
    @SuppressLint("MissingPermission")
    public String getIccid() {
        String iccid = "N/A";
        iccid = telephonyManager.getSimSerialNumber();
        return iccid;
    }

    //获取电话号码
    @SuppressLint("MissingPermission")
    public String getNativePhoneNumber() {
        String nativePhoneNumber = "N/A";
        nativePhoneNumber = telephonyManager.getLine1Number();
        return nativePhoneNumber;
    }

    //获取手机服务商信息
//    public String getProvidersName() {
//        String providersName = "N/A";
//        NetworkOperator = telephonyManager.getNetworkOperator();
//        //IMSI号前面3位460是国家，紧接着后面2位00 02是中国移动，01是中国联通，03是中国电信。
//        if (NetworkOperator.equals("46000") || NetworkOperator.equals("46002")) {
//            providersName = "中国移动";//中国移动
//        } else if (NetworkOperator.equals("46001")) {
//            providersName = "中国联通";//中国联通
//        } else if (NetworkOperator.equals("46003")) {
//            providersName = "中国电信";//中国电信
//        }
//        return providersName;
//    }

//    public String getPhoneInfo() {
//        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//        StringBuffer sb = new StringBuffer();
//        sb.append("\nLine1Number = " + tm.getLine1Number());
//        sb.append("\nNetworkOperator = " + tm.getNetworkOperator());//移动运营商编号
//        sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());//移动运营商名称
//        sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
//        sb.append("\nSimOperator = " + tm.getSimOperator());
//        sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
//        sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
//        sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
//        return sb.toString();
//    }

}